/*"Exposure to Confederate Monuments: The Political Effect of Non-Intervention" 
ANALYSES*/

clear all

*Set working directory* 
cd "H:\Personal\Datos\Confederate paper\Replication\Data\"

* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *
* ············································································ *
							* MAIN ANALYSES *                          
* ············································································ *
* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *

* I standardize all outcome variables to allow for comparison

use dataset.dta, clear

* Standardize signals
foreach var of varlist care_parks care_parking care_equality care_fight_crime ///
conflict_history blm_town blm_personal town_republican town_support_withdrawing_us ///
town_proud_south{
egen std`var' = std(`var')
}
 save dataset.dta, replace
 
 * Standardize emotions
foreach var of varlist anger joy fear pride sadness disgust hostility{
egen std`var' = std(`var')
}
save dataset.dta, replace

 * Attitudinal and quasi-behavioral 
foreach var of varlist good_place_to_live trust_town external_efficacy ///
valued_community donation donationyn{
egen std`var' = std(`var')
}
 save dataset.dta, replace
 


/* I run the main effect for all groups of variables: (1) signals, (2) emotions 
and (3) attitudes and quasi-behavioral outcomes. I will run the analyses both with 
and without controls. */
* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *
* ·································  ATE ····································· *
* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *



* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ SIGNALS ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞*

*First time running test 
clear
gen variable = . 
save signals.dta, replace

* Additional times running test *
use signals.dta, clear
drop _all
gen variable = . 
save signals.dta, replace

use dataset.dta, clear

* Local signals
local signals   stdcare_parks stdcare_parking stdcare_equality stdcare_fight_crime stdconflict_history  stdblm_town stdblm_personal  stdtown_republican  stdtown_support_withdrawing_us stdtown_proud_south            
foreach signal in `signals'{
	regr `signal' treatment, r
	regsave treatment using "signals.dta", ci pval tstat level(95) append addlabel (Signal, `signal', typeout, 1, analysis, 0, subset, 0, Level, 95, Controls, 0)
}

* Local signals. Analyses with controls
local signals   stdcare_parks stdcare_parking stdcare_equality stdcare_fight_crime stdconflict_history  stdblm_town stdblm_personal  stdtown_republican  stdtown_support_withdrawing_us stdtown_proud_south                     
foreach signal in `signals'{
	regr `signal' treatment failacheck nametowncounty, r
	regsave treatment using "signals.dta", ci pval tstat level(95) append addlabel (Signal, `signal', typeout, 1, analysis, 0, subset, 0,  Level, 95, Controls, 2)
}


save dataset.dta, replace

use signals.dta, clear
drop variable
sort Signal
encode Signal, gen(sig)
fre sig

* Reorder variables* 
gen var2 = .
replace var2 = 1 if sig== 5
replace var2 = 2 if sig== 6
replace var2 = 3 if sig== 4
replace var2 = 4 if sig== 3
replace var2 = 5 if sig== 1
replace var2 = 6 if sig== 2
replace var2 = 7 if sig== 10
replace var2 = 8 if sig== 8
replace var2 = 9 if sig== 9
replace var2 = 10 if sig==7

save signals.dta, replace


* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ EMOTIONS ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞*
use dataset.dta, clear


*First time running test 
clear
gen variable = . 
save emotions.dta, replace

* Additional times running test *
use emotions.dta, clear
drop _all
gen variable = . 
save emotions.dta, replace


use dataset.dta, clear


* Local with emotions 
local emotions stdanger stdjoy stdfear stdpride stdsadness stddisgust stdhostility

foreach emotion in `emotions'{
	regr `emotion' treatment, r
	regsave treatment using "emotions.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', typeout, 2, analysis, 0, subset, 0, Level, 95, Controls, 0)
}

* Local with emotions. Analyses with controls
local emotions stdanger stdjoy stdfear stdpride stdsadness stddisgust stdhostility
foreach emotion in `emotions'{
	regr `emotion' treatment failacheck nametowncounty, r
	regsave treatment using "emotions.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', typeout, 2, analysis, 0, subset, 0, Level, 95, Controls, 2)
}


save dataset.dta, replace

use emotions.dta, clear
drop variable
sort Emotion
encode Emotion, gen(emo)
fre emo

* Reorder variables*
gen var2 = .
replace var2 = 1 if emo== 5
replace var2 = 2 if emo== 6
replace var2 = 3 if emo== 7
replace var2 = 4 if emo== 4
replace var2 = 5 if emo== 3
replace var2 = 6 if emo== 2
replace var2 = 7 if emo== 1

save emotions.dta, replace


*∞∞∞∞∞∞∞∞∞∞∞∞∞∞ OUTCOMES:attitudes and quasi-behavioral ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞*


*First time running test 
clear
gen variable = . 
save outcomes.dta, replace

* Additional times running test *
use outcomes.dta, clear
drop _all
gen variable = . 
save outcomes.dta, replace


use dataset.dta, clear

* Local with outcomes *
local outcomes stdgood_place_to_live stdtrust_town stdexternal_efficacy stdvalued_community stddonation stddonationyn
foreach outcome in `outcomes'{
	regr `outcome' treatment, r
	regsave treatment using "outcomes.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', typeout, 3, analysis, 0, subset, 0, Level, 95, Controls, 0)
}

* Local with outcomes. Analyses with controls *
local outcomes stdgood_place_to_live stdtrust_town stdexternal_efficacy stdvalued_community stddonation stddonationyn        
foreach outcome in `outcomes'{
	regr `outcome' treatment failacheck nametowncounty, r
	regsave treatment using "outcomes.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', typeout, 3, analysis, 0, subset, 0, Level, 95, Controls, 2)

}

save dataset.dta, replace

use outcomes.dta, clear
drop variable
sort Outcome
encode Outcome, gen(out)
fre out

* I order the variables *
gen var2 = .
replace var2 = 1 if out== 1
replace var2 = 2 if out== 2
replace var2 = 3 if out== 4
replace var2 = 4 if out== 6
replace var2 = 5 if out== 3
replace var2 = 6 if out== 5

save outcomes.dta, replace

use dataset.dta, clear

/* I create a dataset that includes the main effect for signals, emotions and 
outcomes both with and without controls. Later I will add to this dataset the hte */

*First time running test 
clear
gen variable = . 
save main.dta, replace

* Additional times running test *
use main.dta, clear
drop _all
gen variable = . 
save main.dta, replace


use emotions.dta, clear
recode var2 (1 = 11)
recode var2 (2 = 12)
recode var2 (3 = 13)
recode var2 (4 = 14)
recode var2 (5 = 15)
recode var2 (6 = 16)
recode var2 (7 = 17)
save emotions_r.dta, replace

use outcomes.dta, clear
recode var2 (1 = 18)
recode var2 (2 = 19)
recode var2 (3 = 20)
recode var2 (4 = 21)
recode var2 (5 = 22)
recode var2 (6 = 23)
save outcomes_r.dta, replace

use signals.dta, clear
append using emotions_r outcomes_r
save main.dta, replace


erase signals.dta
erase emotions.dta
erase outcomes.dta
erase emotions_r.dta
erase outcomes_r.dta

*FACETS*
* analysis: 0= ATE, 1 = effect by group, 2 = differences in the effect of treatment (tb calculated)
* typeout: 1 = signals, 2 = emotions, 3 = attitudes
* subset: 0 = main, 1 = Black/Democrat, 2 = White/Republican (tb calculated)
* dataset. 0 = main , 1 = race, 2 = party(tb calculated)




* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *
* ·································  HTE ····································· *
* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *
*__________________________________ RACE______________________________________ *




* ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ SIGNALS INTERACTION RACE ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ *
*______________________________________________________________________________*

*First time running test 
clear
gen variable = . 
save signals_hte_race.dta, replace

clear
gen variable = . 
save difference.dta, replace

* Additional times running test *
use signals_hte_race.dta, clear
drop _all
gen variable = . 
save signals_hte_race.dta, replace

use difference.dta, clear
drop _all
gen variable = .
save difference.dta, replace

use dataset.dta, clear


*HTE race. Difference in the effect of the treatment.
local signals   stdcare_parks stdcare_parking stdcare_equality stdcare_fight_crime stdconflict_history  stdblm_town stdblm_personal  stdtown_republican  stdtown_support_withdrawing_us stdtown_proud_south            
foreach signal in `signals'{
	regr `signal' treatment##black , r
	regsave 1.treatment#1.black using "signals_hte_race.dta", ci pval tstat level(95) append addlabel (Signal, `signal', Level, 95, typeout, 1, Controls, 0, analysis, 2, subset, 0)
	regsave 1.treatment 1.black 1.treatment#1.black using "difference.dta", ci pval tstat level(95) append addlabel (Var, `signal', Level, 95, typeout, 1, Controls, 0, analysis, 2, subset, 0, dataset, 1)
}

*HTE race. Effect for Black respondents. Without controls and with controls
local signals   stdcare_parks stdcare_parking stdcare_equality stdcare_fight_crime stdconflict_history  stdblm_town stdblm_personal  stdtown_republican  stdtown_support_withdrawing_us stdtown_proud_south            
foreach signal in `signals'{
	regr `signal' treatment if black == 1 , r
	regsave treatment using "signals_hte_race.dta", ci pval tstat level(95) append addlabel (Signal, `signal', Level, 95, typeout, 1, Controls, 0, analysis, 1, subset, 1)
	regr `signal' treatment failacheck nametowncounty if black == 1 , r
	regsave treatment failacheck nametowncounty using "signals_hte_race.dta", ci pval tstat level(95) append addlabel (Signal, `signal', Level, 95, typeout, 1, Controls, 2, analysis, 1, subset, 1)
}


*HTE race. Effect for White respondents. Without controls and with controls
* I do not save "nametowncounty" for White respondents as there are no White respondents that recognized the town.
local signals   stdcare_parks stdcare_parking stdcare_equality stdcare_fight_crime stdconflict_history  stdblm_town stdblm_personal  stdtown_republican  stdtown_support_withdrawing_us stdtown_proud_south            
foreach signal in `signals'{
	regr `signal' treatment if white == 1 , r
	regsave treatment using "signals_hte_race.dta", ci pval tstat level(95) append addlabel (Signal, `signal', Level, 95, typeout, 1, Controls, 0, analysis, 1, subset, 2)
	regr `signal' treatment failacheck nametowncounty if white == 1 , r
	regsave treatment failacheck using "signals_hte_race.dta", ci pval tstat level(95) append addlabel (Signal, `signal', Level, 95, typeout, 1, Controls, 2, analysis, 1, subset, 2)
}

save dataset.dta, replace



use signals_hte_race.dta, clear
drop variable
sort Signal
encode Signal, gen(sig)
fre sig


gen var2 = .
replace var2 = 1 if sig== 5
replace var2 = 2 if sig== 6
replace var2 = 3 if sig== 4
replace var2 = 4 if sig== 3
replace var2 = 5 if sig== 1
replace var2 = 6 if sig== 2
replace var2 = 7 if sig== 10
replace var2 = 8 if sig== 8
replace var2 = 9 if sig== 9
replace var2 = 10 if sig==7

save signals_hte_race.dta, replace



* ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨   EMOTION INTERACTION RACE  ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ *
*______________________________________________________________________________*

*First time running test 
clear
gen variable = . 
save emotions_hte_race.dta, replace

* Additional times running test *
use emotions_hte_race.dta, clear
drop _all
gen variable = . 
save emotions_hte_race.dta, replace

use dataset.dta, clear

* Difference in the effect of the treatment for Black and White individuals
local emotions stdanger stdjoy stdfear stdpride stdsadness stddisgust stdhostility
foreach emotion in `emotions'{
	regr `emotion' treatment##black , r
	regsave 1.treatment#1.black  using "emotions_hte_race.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', Level, 95, typeout, 2, Controls, 0, analysis, 2, subset, 0)
	regsave 1.treatment 1.black 1.treatment#1.black using "difference.dta", ci pval tstat level(95) append addlabel (Var, `emotion',  Level, 95, typeout, 2, Controls, 0, analysis, 2, subset, 0, dataset, 1)
}


* Effect for Black respondents
local emotions stdanger stdjoy stdfear stdpride stdsadness stddisgust stdhostility
foreach emotion in `emotions'{
	regr `emotion' treatment if black == 1 , r
	regsave treatment using "emotions_hte_race.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', Level, 95, typeout, 2, Controls, 0, analysis, 1, subset, 1)
	regr `emotion' treatment failacheck nametowncounty if black == 1 , r
	regsave treatment failacheck nametowncounty  using "emotions_hte_race.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', Level, 95, typeout, 2, Controls, 2, analysis, 1, subset, 1)
}



* Effect for White respondents
* I do not save "nametowncounty" for White respondents as there are no White respondents that recognized the town.
local emotions stdanger stdjoy stdfear stdpride stdsadness stddisgust stdhostility
foreach emotion in `emotions'{
	regr `emotion' treatment if white == 1, r
	regsave treatment  using "emotions_hte_race.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', Level, 95, typeout, 2, Controls, 0, analysis, 1, subset, 2)
	regr `emotion' treatment failacheck nametowncounty if white == 1, r
	regsave treatment failacheck using "emotions_hte_race.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', Level, 95, typeout, 2, Controls, 2, analysis, 1, subset, 2)
}

save dataset.dta, replace

use emotions_hte_race.dta, clear
drop variable
sort Emotion
encode Emotion, gen(emo)
fre emo


gen var2 = .
replace var2 = 1 if emo== 5
replace var2 = 2 if emo== 6
replace var2 = 3 if emo== 7
replace var2 = 4 if emo== 4
replace var2 = 5 if emo== 3
replace var2 = 6 if emo== 2
replace var2 = 7 if emo== 1

save emotions_hte_race.dta, replace




* ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ OUTCOMES INTERACTION RACE ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ *
*______________________________________________________________________________*

*First time running test 
clear
gen variable = . 
save outcomes_hte_race.dta, replace

* Additional times running test *
use outcomes_hte_race.dta, clear
drop _all
gen variable = . 
save outcomes_hte_race.dta, replace


use dataset.dta, clear

* Difference in the effect of the treatment
local outcomes stdgood_place_to_live stdtrust_town stdexternal_efficacy stdvalued_community stddonation stddonationyn
foreach outcome in `outcomes'{
	regr `outcome' treatment##black, r
	regsave 1.treatment#1.black using "outcomes_hte_race.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', Level, 95, typeout, 3, Controls, 0, analysis, 2, subset, 0)
	regsave 1.treatment 1.black 1.treatment#1.black using "difference.dta", ci pval tstat level(95) append addlabel (Var, `outcome',  Level, 95, typeout, 3, Controls, 0, analysis, 2, subset, 0, dataset, 1)
}

* Effect for Black individuals
local outcomes stdgood_place_to_live stdtrust_town stdexternal_efficacy stdvalued_community stddonation stddonationyn
foreach outcome in `outcomes'{
	regr `outcome' treatment if black==1, r
	regsave treatment using "outcomes_hte_race.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', Level, 95, typeout, 3, Controls, 0, analysis, 1, subset, 1)
	regr `outcome' treatment failacheck nametowncounty  if black==1, r
	regsave treatment failacheck nametowncounty  using "outcomes_hte_race.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', Level, 95, typeout, 3, Controls, 2, analysis, 1, subset, 1)
}


* Effect for White individuals
* I do not save "nametowncounty" for White respondents as there are no White respondents that recognized the town.
local outcomes stdgood_place_to_live stdtrust_town stdexternal_efficacy stdvalued_community stddonation stddonationyn
foreach outcome in `outcomes'{
	regr `outcome' treatment if white == 1, r
	regsave treatment  using "outcomes_hte_race.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', Level, 95, typeout, 3, Controls, 0, analysis, 1, subset, 2)
	regr `outcome' treatment failacheck nametowncounty if white == 1, r
	regsave treatment failacheck using "outcomes_hte_race.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', Level, 95, typeout, 3, Controls, 2, analysis, 1, subset, 2)
}


save dataset.dta, replace

use outcomes_hte_race.dta, clear
drop variable
sort Outcome
encode Outcome, gen(out)
fre out


gen var2 = .
replace var2 = 1 if out== 1
replace var2 = 2 if out== 2
replace var2 = 3 if out== 4
replace var2 = 4 if out== 6
replace var2 = 5 if out== 3
replace var2 = 6 if out== 5


save outcomes_hte_race.dta, replace


* I put all three race datasets together.

*First time running test 
clear
gen variable = . 
save race.dta, replace

* Additional times running test *
use race.dta, clear
drop _all
gen variable = . 
save race.dta, replace


use emotions_hte_race.dta, clear
recode var2 (1 = 11)
recode var2 (2 = 12)
recode var2 (3 = 13)
recode var2 (4 = 14)
recode var2 (5 = 15)
recode var2 (6 = 16)
recode var2 (7 = 17)
save emotions_hte_race_r.dta, replace

use outcomes_hte_race.dta, clear
recode var2 (1 = 18)
recode var2 (2 = 19)
recode var2 (3 = 20)
recode var2 (4 = 21)
recode var2 (5 = 22)
recode var2 (6 = 23)

save outcomes_hte_race_r.dta, replace

use signals_hte_race.dta, clear
append using emotions_hte_race_r outcomes_hte_race_r
save race.dta, replace

erase signals_hte_race.dta
erase emotions_hte_race.dta
erase outcomes_hte_race.dta
erase emotions_hte_race_r.dta
erase outcomes_hte_race_r.dta


* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *
* ·································  HTE ····································· *
* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *
*_______________________________ POL. ID _____________________________________ *



* ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ SIGNALS INTERACTION PARTY ID ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ *
*______________________________________________________________________________*


*First time running test 
clear
gen variable = . 
save signals_hte_party.dta, replace

* Additional times running the test*
use signals_hte_party.dta, clear
drop _all
gen variable = . 
save signals_hte_party.dta, replace

use dataset.dta, clear


* Difference in the effect of the treatment
local signals   stdcare_parks stdcare_parking stdcare_equality stdcare_fight_crime stdconflict_history  stdblm_town stdblm_personal  stdtown_republican  stdtown_support_withdrawing_us stdtown_proud_south            
foreach signal in `signals'{
	regr `signal' treatment##democratlean , r
	regsave 1.treatment#1.democratlean using "signals_hte_party.dta", ci pval tstat level(95) append addlabel (Signal, `signal', Level, 95, typeout, 1, Controls, 0, analysis, 2, subset, 0)
	regsave 1.treatment 1.democratlean 1.treatment#1.democratlean using "difference.dta", ci pval tstat level(95) append addlabel (Var, `signal',  Level, 95, typeout, 1, Controls, 0, analysis, 2, subset, 0, dataset, 2)
}


* Effect for Democrats
local signals   stdcare_parks stdcare_parking stdcare_equality stdcare_fight_crime stdconflict_history  stdblm_town stdblm_personal  stdtown_republican  stdtown_support_withdrawing_us stdtown_proud_south            
foreach signal in `signals'{
	regr `signal' treatment if democratlean == 1 , r
	regsave treatment using "signals_hte_party.dta", ci pval tstat level(95) append addlabel (Signal, `signal', Level, 95, typeout, 1, Controls, 0, analysis, 1, subset, 1)
	regr `signal' treatment failacheck nametowncounty if democratlean == 1 , r
	regsave treatment using "signals_hte_party.dta", ci pval tstat level(95) append addlabel (Signal, `signal', Level, 95, typeout, 1, Controls, 2, analysis, 1, subset, 1)
}

* Effect for Republicans
* I do not save "nametowncounty" for Republican respondents as there are no Republican respondents that recognized the town.
local signals   stdcare_parks stdcare_parking stdcare_equality stdcare_fight_crime stdconflict_history  stdblm_town stdblm_personal  stdtown_republican  stdtown_support_withdrawing_us stdtown_proud_south            
foreach signal in `signals'{
	regr `signal' treatment if republicanlean== 1 , r
	regsave treatment using "signals_hte_party.dta", ci pval tstat level(95) append addlabel (Signal, `signal', Level, 95, typeout, 1, Controls, 0, analysis, 1, subset, 2)
	regr `signal' treatment failacheck nametowncounty if republicanlean== 1 , r
	regsave treatment failacheck using "signals_hte_party.dta", ci pval tstat level(95) append addlabel (Signal, `signal', Level, 95, typeout, 1, Controls, 2, analysis, 1, subset, 2)
}


save dataset.dta, replace

use signals_hte_party.dta, clear
drop variable
sort Signal
encode Signal, gen(sig)
fre sig


gen var2 = .
replace var2 = 1 if sig== 5
replace var2 = 2 if sig== 6
replace var2 = 3 if sig== 4
replace var2 = 4 if sig== 3
replace var2 = 5 if sig== 1
replace var2 = 6 if sig== 2
replace var2 = 7 if sig== 10
replace var2 = 8 if sig== 8
replace var2 = 9 if sig== 9
replace var2 = 10 if sig==7

save signals_hte_party.dta, replace



* ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ EMOTIONS INTERACTION PARTY ID ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ *
*______________________________________________________________________________*



*First time running test 
clear
gen variable = . 
save emotions_hte_party.dta, replace

* Additional times running the test*
use emotions_hte_party.dta, clear
drop _all
gen variable = . 
save emotions_hte_party.dta, replace


use dataset.dta, clear


* Difference in the effect of the treatment
local emotions stdanger stdjoy stdfear stdpride stdsadness stddisgust stdhostility
foreach emotion in `emotions'{
	regr `emotion' treatment##democratlean, r
	regsave 1.treatment#1.democratlean  using "emotions_hte_party.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', Level, 95,  typeout, 2, Controls, 0, analysis, 2, subset, 0)
	regsave 1.treatment 1.democratlean 1.treatment#1.democratlean using "difference.dta", ci pval tstat level(95) append addlabel (Var, `emotion',  Level, 95, typeout, 2, Controls, 0, analysis, 2, subset, 0, dataset, 2)

}


* Effect for Democrats
local emotions stdanger stdjoy stdfear stdpride stdsadness stddisgust stdhostility
foreach emotion in `emotions'{
	regr `emotion' treatment if democratlean == 1 , r
	regsave treatment  using "emotions_hte_party.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', Level, 95, typeout, 2, Controls, 0, analysis, 1, subset, 1)
	regr `emotion' treatment failacheck nametowncounty if democratlean == 1 , r
	regsave treatment failacheck nametowncounty  using "emotions_hte_party.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', Level, 95, typeout, 2, Controls, 2, analysis, 1, subset, 1)
}


* Effect for Republicans
* I do not save "nametowncounty" for Republican respondents as there are no Republican respondents that recognized the town.

local emotions stdanger stdjoy stdfear stdpride stdsadness stddisgust stdhostility
foreach emotion in `emotions'{
	regr `emotion' treatment if republicanlean == 1 , r
	regsave treatment  using "emotions_hte_party.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', Level, 95, typeout, 2, Controls, 0, analysis, 1, subset, 2)
	regr `emotion' treatment failacheck nametowncounty if republicanlean == 1 , r
	regsave treatment failacheck using "emotions_hte_party.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', Level, 95, typeout, 2, Controls, 2, analysis, 1, subset, 2)
}


save dataset.dta, replace

use emotions_hte_party.dta, clear
drop variable
sort Emotion
encode Emotion, gen(emo)
fre emo


gen var2 = .
replace var2 = 1 if emo== 5
replace var2 = 2 if emo== 6
replace var2 = 3 if emo== 7
replace var2 = 4 if emo== 4
replace var2 = 5 if emo== 3
replace var2 = 6 if emo== 2
replace var2 = 7 if emo== 1

save emotions_hte_party.dta, replace



* ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ OUTCOME INTERACTION PARTY ID ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ *
*______________________________________________________________________________*


*First time running test 
clear
gen variable = . 
save outcomes_hte_party.dta, replace

* Additional times running the test*
use outcomes_hte_party.dta, clear
drop _all
gen variable = . 
save outcomes_hte_party.dta, replace

use dataset.dta, clear

* Difference in the effect of the treatment
local outcomes stdgood_place_to_live stdtrust_town stdexternal_efficacy stdvalued_community stddonation stddonationyn
foreach outcome in `outcomes'{
	regr `outcome' treatment##democratlean , r
	regsave 1.treatment#1.democratlean using "outcomes_hte_party.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', Level, 95, typeout, 3, Controls, 0, analysis, 2, subset, 0)
	regsave 1.treatment 1.democratlean 1.treatment#1.democratlean using "difference.dta", ci pval tstat level(95) append addlabel (Var, `outcome',  Level, 95, typeout, 3, Controls, 0, analysis, 2, subset, 0, dataset, 2)
}

* Effect for Democracts
local outcomes stdgood_place_to_live stdtrust_town stdexternal_efficacy stdvalued_community stddonation stddonationyn
foreach outcome in `outcomes'{
	regr `outcome' treatment if democratlean==1 , r
	regsave treatment using "outcomes_hte_party.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', Level, 95, typeout, 3, Controls, 0, analysis, 1, subset, 1)
	regr `outcome' treatment failacheck nametowncounty if democratlean==1 , r
	regsave treatment using "outcomes_hte_party.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', Level, 95, typeout, 3, Controls, 2, analysis, 1, subset, 1)
}



* Effect for Republicans
* I do not save "nametowncounty" for Republican respondents as there are no Republican respondents that recognized the town.

local outcomes stdgood_place_to_live stdtrust_town stdexternal_efficacy stdvalued_community stddonation stddonationyn
foreach outcome in `outcomes'{
	regr `outcome' treatment if republicanlean==1 , r
	regsave treatment using "outcomes_hte_party.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', Level, 95, typeout, 3, Controls, 0, analysis, 1, subset, 2)
	regr `outcome' treatment failacheck nametowncounty if republicanlean==1 , r
	regsave treatment failacheck using "outcomes_hte_party.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', Level, 95, typeout, 3, Controls, 2, analysis, 1, subset, 2)
}


save dataset.dta, replace

use outcomes_hte_party.dta, clear
drop variable
sort Outcome
encode Outcome, gen(out)
fre out

gen var2 = .
replace var2 = 1 if out== 1
replace var2 = 2 if out== 2
replace var2 = 3 if out== 4
replace var2 = 4 if out== 6
replace var2 = 5 if out== 3
replace var2 = 6 if out== 5

save outcomes_hte_party.dta, replace


* I put all three party ID datasets together.
*First time running test 
clear
gen variable = . 
save party.dta, replace

* Additional times running test *
use party.dta, clear
drop _all
gen variable = .
save party.dta, replace


use emotions_hte_party.dta, clear
recode var2 (1 = 11)
recode var2 (2 = 12)
recode var2 (3 = 13)
recode var2 (4 = 14)
recode var2 (5 = 15)
recode var2 (6 = 16)
recode var2 (7 = 17)
save emotions_hte_party_r.dta, replace

use outcomes_hte_party.dta, clear
recode var2 (1 = 18)
recode var2 (2 = 19)
recode var2 (3 = 20)
recode var2 (4 = 21)
recode var2 (5 = 22)
recode var2 (6 = 23)
save outcomes_hte_party_r.dta, replace

use signals_hte_party.dta, clear
append using emotions_hte_party_r outcomes_hte_party_r
save party.dta, replace

erase signals_hte_party.dta
erase emotions_hte_party.dta
erase outcomes_hte_party.dta
erase emotions_hte_party_r.dta 
erase outcomes_hte_party_r.dta


* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *
* ························· MERGE MAIN, RACE, ID ····························· *
* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *
/* I now create the table with all three datasets: main, race and party ID. This
table is used to create Figures 5 and 6 in the manuscript and Tables A.3, A.4,
A.7., A.8., A.9. in appendix. 

Full sampe = subset 0
Black individuals = dataset 1, subset 1
White individuals = dataset 1, subset 2
Democrats = dataset 2, subset 1
Republicans = dataset 2, subset 2

Main effect = analysis 0
Treatment effect for a subset= analysis 1
Difference in the effect of the treatment = analysis 2


Signals = typeout 1
Emotions = typeout 2
Attitudes and semibehavioral = typeout 3
*/

use race.dta, clear
gen dataset = 1
save race.dta, replace

use party.dta, clear
gen dataset = 2
save party.dta, replace

use main.dta, clear
gen dataset = 0
append using race party
save main_hte.dta, replace


* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *
* ············································································ *
			* ADDITIONAL ANALYSES IN APPENDIX, FIGURE E.1 *                          
* ············································································ *
* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *


* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *
* ·································  HTE ····································· *
* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ *
*___________ Sense of belonging to a Deep South State ________________________ *



* ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ SIGNALS INTERACTION Deep South belong ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ *
*______________________________________________________________________________*


*First time running test 
clear
gen variable = . 
save signals_hte_deepbelong.dta, replace

* Additional times running the test*
use signals_hte_deepbelong.dta, clear
drop _all
gen variable = . 
save signals_hte_deepbelong.dta, replace

use dataset.dta, clear


* Difference in the effect of the treatment
local signals   stdcare_parks stdcare_parking stdcare_equality stdcare_fight_crime stdconflict_history  stdblm_town stdblm_personal  stdtown_republican  stdtown_support_withdrawing_us stdtown_proud_south            
foreach signal in `signals'{
	regr `signal' treatment##deepbelong , r
	regsave 1.treatment#1.deepbelong using "signals_hte_deepbelong.dta", ci pval tstat level(95) append addlabel (Signal, `signal', Level, 95, typeout, 1, Controls, 0, analysis, 2, subset, 0)
}


*  Effect for those with a sense of belonging to a Deep South state
local signals   stdcare_parks stdcare_parking stdcare_equality stdcare_fight_crime stdconflict_history  stdblm_town stdblm_personal  stdtown_republican  stdtown_support_withdrawing_us stdtown_proud_south            
foreach signal in `signals'{
	regr `signal' treatment if deepbelong == 1 , r
	regsave treatment using "signals_hte_deepbelong.dta", ci pval tstat level(95) append addlabel (Signal, `signal', Level, 95, typeout, 1, Controls, 0, analysis, 1, subset, 1)
}

*  Effect for those without a sense of belonging to a Deep South state
local signals   stdcare_parks stdcare_parking stdcare_equality stdcare_fight_crime stdconflict_history  stdblm_town stdblm_personal  stdtown_republican  stdtown_support_withdrawing_us stdtown_proud_south            
foreach signal in `signals'{
	regr `signal' treatment if deepbelong== 0 , r
	regsave treatment using "signals_hte_deepbelong.dta", ci pval tstat level(95) append addlabel (Signal, `signal', Level, 95, typeout, 1, Controls, 0, analysis, 1, subset, 2)
}


save dataset.dta, replace

use signals_hte_deepbelong.dta, clear
drop variable
sort Signal
encode Signal, gen(sig)
fre sig


gen var2 = .
replace var2 = 1 if sig== 5
replace var2 = 2 if sig== 6
replace var2 = 3 if sig== 4
replace var2 = 4 if sig== 3
replace var2 = 5 if sig== 1
replace var2 = 6 if sig== 2
replace var2 = 7 if sig== 10
replace var2 = 8 if sig== 8
replace var2 = 9 if sig== 9
replace var2 = 10 if sig==7

save signals_hte_deepbelong.dta, replace



* ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ EMOTIONS INTERACTION Deep South belong ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ *
*______________________________________________________________________________*



*First time running test 
clear
gen variable = . 
save emotions_hte_deepbelong.dta, replace

* Additional times running the test*
use emotions_hte_deepbelong.dta, clear
drop _all
gen variable = . 
save emotions_hte_deepbelong.dta, replace


use dataset.dta, clear


* Difference in the effect of the treatment
local emotions stdanger stdjoy stdfear stdpride stdsadness stddisgust stdhostility
foreach emotion in `emotions'{
	regr `emotion' treatment##deepbelong, r
	regsave 1.treatment#1.deepbelong  using "emotions_hte_deepbelong.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', Level, 95,  typeout, 2, Controls, 0, analysis, 2, subset, 0)
}


* Effect for those with a sense of belonging to a Deep South state
local emotions stdanger stdjoy stdfear stdpride stdsadness stddisgust stdhostility
foreach emotion in `emotions'{
	regr `emotion' treatment if deepbelong == 1 , r
	regsave treatment  using "emotions_hte_deepbelong.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', Level, 95, typeout, 2, Controls, 0, analysis, 1, subset, 1)
}


*  Effect for those without a sense of belonging to a Deep South state
local emotions stdanger stdjoy stdfear stdpride stdsadness stddisgust stdhostility
foreach emotion in `emotions'{
	regr `emotion' treatment if deepbelong == 0 , r
	regsave treatment  using "emotions_hte_deepbelong.dta", ci pval tstat level(95) append addlabel (Emotion, `emotion', Level, 95, typeout, 2, Controls, 0, analysis, 1, subset, 2)
}


save dataset.dta, replace

use emotions_hte_deepbelong.dta, clear
drop variable
sort Emotion
encode Emotion, gen(emo)
fre emo


gen var2 = .
replace var2 = 1 if emo== 5
replace var2 = 2 if emo== 6
replace var2 = 3 if emo== 7
replace var2 = 4 if emo== 4
replace var2 = 5 if emo== 3
replace var2 = 6 if emo== 2
replace var2 = 7 if emo== 1

save emotions_hte_deepbelong.dta, replace



* ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ OUTCOME INTERACTION Deep South belong ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ *
*______________________________________________________________________________*


*First time running test 
clear
gen variable = . 
save outcomes_hte_deepbelong.dta, replace

* Additional times running the test*
use outcomes_hte_deepbelong.dta, clear
drop _all
gen variable = . 
save outcomes_hte_deepbelong.dta, replace

use dataset.dta, clear

* Difference in the effect of the treatment
local outcomes stdgood_place_to_live stdtrust_town stdexternal_efficacy stdvalued_community stddonation stddonationyn
foreach outcome in `outcomes'{
	regr `outcome' treatment##deepbelong , r
	regsave 1.treatment#1.deepbelong using "outcomes_hte_deepbelong.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', Level, 95, typeout, 3, Controls, 0, analysis, 2, subset, 0)
}

*  Effect for those with a sense of belonging to a Deep South state
local outcomes stdgood_place_to_live stdtrust_town stdexternal_efficacy stdvalued_community stddonation stddonationyn
foreach outcome in `outcomes'{
	regr `outcome' treatment if deepbelong==1 , r
	regsave treatment using "outcomes_hte_deepbelong.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', Level, 95, typeout, 3, Controls, 0, analysis, 1, subset, 1)
}


*  Effect for those without a sense of belonging to a Deep South state
local outcomes stdgood_place_to_live stdtrust_town stdexternal_efficacy stdvalued_community stddonation stddonationyn
foreach outcome in `outcomes'{
	regr `outcome' treatment if deepbelong==0 , r
	regsave treatment using "outcomes_hte_deepbelong.dta", ci pval tstat level(95) append addlabel (Outcome, `outcome', Level, 95, typeout, 3, Controls, 0, analysis, 1, subset, 2)
}

save dataset.dta, replace

use outcomes_hte_deepbelong.dta, clear
drop variable
sort Outcome
encode Outcome, gen(out)
fre out

gen var2 = .
replace var2 = 1 if out== 1
replace var2 = 2 if out== 2
replace var2 = 3 if out== 4
replace var2 = 4 if out== 6
replace var2 = 5 if out== 3
replace var2 = 6 if out== 5

save outcomes_hte_deepbelong.dta, replace


* I put all three sense-of-belonging datasets together.
*First time running test 
clear
gen variable = . 
save deepsouth.dta, replace

* Additional times running test *
use deepsouth.dta, clear
drop _all
gen variable = .
save deepsouth.dta, replace


use emotions_hte_deepbelong.dta, clear
recode var2 (1 = 11)
recode var2 (2 = 12)
recode var2 (3 = 13)
recode var2 (4 = 14)
recode var2 (5 = 15)
recode var2 (6 = 16)
recode var2 (7 = 17)
save emotions_hte_deepbelong_r.dta, replace

use outcomes_hte_deepbelong.dta, clear
recode var2 (1 = 18)
recode var2 (2 = 19)
recode var2 (3 = 20)
recode var2 (4 = 21)
recode var2 (5 = 22)
recode var2 (6 = 23)
save outcomes_hte_deepbelong_r.dta, replace

use signals_hte_deepbelong.dta, clear
append using emotions_hte_deepbelong_r outcomes_hte_deepbelong_r
gen dataset = 4
save deepsouth.dta, replace

erase signals_hte_deepbelong.dta
erase emotions_hte_deepbelong.dta
erase outcomes_hte_deepbelong.dta
erase emotions_hte_deepbelong_r.dta 
erase outcomes_hte_deepbelong_r.dta




